package com.itheima.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String user = (String) request.getSession().getAttribute("user");

        if (user == null) {
            System.out.println("用户未登录");
            return false;
        } else {
            System.out.println("用户已经登录");
            return true;
        }

    }
}
